//
//  FifthViewController.m
//  Streaming
//
//  Created by 韩一博 on 15/7/1.
//  Copyright (c) 2015年 liuxun. All rights reserved.
//

#import "FifthViewController.h"

@interface FifthViewController ()

@end

@implementation FifthViewController

- (void)dealloc
{
    [self.tableView release];
    [self.array release];
    
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view setBackgroundColor:[UIColor whiteColor]];
    self.navigationItem.title = @"流媒体资讯";
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"我的" style:UIBarButtonItemStyleDone target:self action:@selector(leftBarButtonItemAction)];
    [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:31/255.0 green:115/255.0 blue:192/255.0 alpha:0.3]];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
    
    [self creatTable];
    
}


- (void)leftBarButtonItemAction
{
    [self.sideMenuViewController presentLeftMenuViewController];
}

- (void)creatTable
{
    self.tableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] bounds] style:UITableViewStylePlain];
    [self.tableView setBackgroundColor:[UIColor whiteColor]];
    [self.view addSubview:self.tableView];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    self.navigationItem.rightBarButtonItem = self.editButtonItem;
    [self.tableView release];
    
}
//导航栏右侧按钮触发
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
    [super setEditing:editing animated:animated];
    [self.tableView setEditing:editing animated:animated];
    
}
//询问哪些行需要编辑
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}
//设计编辑类型
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleDelete;
}
//按钮实现
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    web *webIDD = [self.array objectAtIndex:indexPath.row];
    [[DateHandel shareHandle]deleteCollectTable:webIDD.idd];
    
    [self.tableView reloadData];
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    self.array = [[DateHandel shareHandle]selectAllCollect];
    
    return self.array.count;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        
    }
    
    NSArray *array = [[DateHandel shareHandle]selectAllCollect];
    
    NSMutableArray *arr = [NSMutableArray array];
    for (web *webIDD in array) {
        [arr addObject:webIDD.title1];
        NSLog(@"webIDD = %@", webIDD.title1);
        
    }
    [cell.textLabel setText:[arr objectAtIndex:indexPath.row]];
    
    
    
    
    return cell;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    RealDetailsViewController *realDVC = [[RealDetailsViewController alloc] init];
    
    
    
    NSMutableArray *array = [[DateHandel shareHandle]selectAllCollect];
    
    
    web *webIDD = [array objectAtIndex:indexPath.row];
    NSInteger i = [webIDD.idd integerValue];
    realDVC.newsId = i;
    //    MdetailsVC. = array[indexPath.row];
    //    NSLog(@"222222%@", array[indexPath.row]);
    [self.navigationController pushViewController:realDVC animated:YES];
    [realDVC release];
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
